<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<script src="<%=path%>/static/jquery/jquery-3.6.0.min.js"></script>
<script src="<%=path%>/static/hui/lib/layer/2.4/layer.js"></script>
<script src="<%=path%>/static/js/common.js"></script>
<link href="<%=path%>/static/modal/bootstrap-4.6.0-dist/css/bootstrap.min.css" rel="stylesheet"/>

<html>
<head>
    <title>Title</title>
</head>
<body class="body">
<div class="page-container">
    <div class="container-md m-3">
        <div id="filePickerContainer">
            <form class="form" onsubmit="return false;">
                <div class="form-group">
                    <label>姓名</label>
                    <input class="form-control" type="text" name="a_name" id="a_name" placeholder="真实姓名">
                </div>
                <div class="form-group">
                    <label>性别</label>
                    <input class="form-control" type="text" name="a_sex" id="a_sex" placeholder="请输入性别">
                </div>
                <div class="form-group">
                    <label>账号</label>
                    <input class="form-control" type="text" <%--onblur="check()"--%> name="a_username" id="a_username"
                           placeholder="请输入账号">
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input class="form-control" type="text" name="a_password" id="a_password" placeholder="请输入密码">
                </div>
                <div class="col">
                    <div class="laydate-footer-btns right-button">
                        <button class="btn btn-success float-right btn-lg" type="button" onclick="addOneAdmin()">提交
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script src="<%=path%>/static/jquery/jquery-3.6.0.min.js"></script>
<script>
    function addOneAdmin() {
        var a_name = $("#a_name").val();
        var a_sex = $("#a_sex").val();
        var a_username = $("#a_username").val();
        var a_password = $("#a_password").val();
        //判断用户是否输入全部信息
        if ((a_name != null || a_name != "") && (a_sex != null || a_sex != "")
            && (a_username != null || a_username != "") && (a_password != null || a_password != "")) {
            $.ajax({
                url: "addOneAdmin",
                method: "post",
                dataType: "text",
                /*contentType:"application/x-www.-form-urlencoded",*/
                data: {
                    a_name: a_name,
                    a_sex: a_sex,
                    a_username: a_username,
                    a_password: a_password,
                },
                success: function (result) {
                    if (result == "success") {
                        alert("添加成功");
                        //刷新父层
                        parent.location.reload();
                        //关闭本层
                        layer_close();
                    } else {
                        alert("添加失败");
                    }
                }, error: function (e) {
                    alert("服务器错误");
                }
            })
        } else {
            alert("请输入全部信息");
        }
    }

    /*function check() {
        $.ajax({
            url:"checkAdmin",
            method:"post",
            dataType: "text",
            /!*contentType:"application/x-www.-form-urlencoded",*!/
            data:{
                a_username:$("#a_username").val()
            },
            success:function (result) {
                if(result == "success"){
                }else {
                    alert("该用户已存在");
                }
            },error:function (e) {
                alert("服务器错误");
            }
        })
    }*/
</script>
</html>
